package com.example.fw;

import java.util.List;
import java.util.Set;

import org.hibernate.Session;
import org.hibernate.Transaction;

public class HibernateHelper extends HelperBase {

	public HibernateHelper(ApplicationManager manager) {
		super(manager);
	}

	public String getLastGroupId() {
		Session session = HibernateUtil.getSessionFactory().getCurrentSession();
		Transaction t = session.beginTransaction();
		try {
		return session.createQuery("select max(id) from GroupObject").uniqueResult().toString();
		} finally {
			t.commit();
		}
	}

	public Groups listGroups() {
		Session session = HibernateUtil.getSessionFactory().getCurrentSession();
		Transaction t = session.beginTransaction();
		try {
		return new Groups ((List<GroupObject>) session.createQuery("from GroupObject").list());
		} finally {
			t.commit();
		}
	}

	public String getLastContactId() {
		Session session = HibernateUtil.getSessionFactory().getCurrentSession();
		Transaction t = session.beginTransaction();
		try {
		return session.createQuery("select max(id) from ContactObject").uniqueResult().toString();
		} finally {
			t.commit();
		}
	}

	public Contacts listContacts() {
		Session session = HibernateUtil.getSessionFactory().getCurrentSession();
		Transaction t = session.beginTransaction();
		try {
		return new Contacts ((List<ContactObject>) session.createQuery("from ContactObject").list());
		} finally {
			t.commit();
		}
	}
}
